# 存储数据
users = [
    {
        'id':1,
        'username':'admin',
        'password':'123',
    }
]
students = {
    1001:{
        'id':1001,
        'name':'aaa',
        'age':18,
        'sex':'男',
        'height':180.4,
        'major':'软件工程'
    },
    1002:{
        'id':1002,
        'name':'bbb',
        'age':22,
        'sex':'女',
        'height':160.5,
        'major':'互联网'
    },
    
}
id = 1003 # 序列值，表示学号


print('====================欢迎使用学生管理系统=======================')
while True:
    print('----------------------------')
    print('1.登陆')
    print('2.注册')
    choice = int(input('请选择：'))
    if choice == 1:
        username = input('请输入用户名：')
        password = input('请输入密码：')
        # 判断是否登陆成功
        isSuccess = False
        for user in users:
            if user['username'] == username and user['password'] == password:
                isSuccess = True
                break 
        if isSuccess:
            print(f'欢迎您：{username}！')
            while True:
                print('-------------------------')
                print('1.查询所有学生')
                print('2.根据学号查询学生')
                print('3.添加学生')
                print('4.修改学生')
                print('5.删除学生')
                print('6.退出')    
                choice = int(input('请选择：'))
                if choice == 1:
                    print('学号\t\t姓名\t\t年龄\t\t性别\t\t身高\t\t专业')
                    for stu in students.values():
                        print(stu['id'],stu['name'],stu['age'],stu['sex'],stu['height'],stu['major'],sep='\t\t')
                elif choice == 2:
                    sid = int(input('请输入要查询的学生学号：'))
                    if sid in students:
                        stu = students[sid]
                        print('学号\t\t姓名\t\t年龄\t\t性别\t\t身高\t\t专业')
                        print(stu['id'],stu['name'],stu['age'],stu['sex'],stu['height'],stu['major'],sep='\t\t')
                    else:
                        print(f'未找到学号为{sid}的学生！')    
                elif choice == 3:
                    name = input('请输入姓名：')
                    for stu in students.values():
                        if stu['name'] == name:
                            name = name + '2'
                            break
                    age = int(input('请输入年龄：'))
                    sex = input('请输入性别：')
                    height = float(input('请输入身高：'))
                    major = input('请输入专业：')
                    stu = {
                        'id':id,
                        'name':name,
                        'age':age,
                        'sex':sex,
                        'height':height,
                        'major':major
                    }
                    students[id] = stu
                    id += 1
                    print('添加成功！')
                elif choice == 4:
                    sid = int(input('请输入要修改的学生学号：'))
                    if sid in students:
                        students[sid]['name'] = input('请输入修改的姓名：')
                        students[sid]['age'] = int(input('请输入修改的年龄：'))
                        students[sid]['sex'] = input('请输入修改的性别：')
                        students[sid]['height'] = float(input('请输入修改的身高：'))
                        students[sid]['major'] = input('请输入修改的专业：')
                        print('修改成功！')
                    else:
                        print(f'未找到学号为{sid}的学生！')    
                elif choice == 5:
                    sid = int(input('请输入要删除的学生学号：'))
                    if sid in students:
                        del students[sid]
                        print('删除成功！')
                    else:
                        print(f'未找到学号为{sid}的学生！')     
                elif choice == 6:
                    break    
        else:
            print('登陆失败，用户名或密码不正确！')
    elif choice == 2:
        username = input('请输入用户名：')
        password = input('请输入密码：')
        repassword = input('请再次输入密码：')
        # 判断用户名是否已存在 
        isExist = False 
        for user in users:
            if user['username'] == username:
                isExist = True
                break
        if isExist:
            print('用户名已存在，请重新注册！')        
        elif password != repassword:
            print('两次输入的密码不一致，请重新注册！')
        else:    
            # 新增账户
            user = {
                'id':len(users) + 1,
                'username':username,
                'password':password
            }
            users.append(user)
            print('注册成功！',users)